﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SILAS.Entidades;
using SILAS.BL;
using Microsoft.Practices.Unity;
using System.IO;
using SILAS.UI.Models;

namespace SILAS.UI.Controllers
{
    public class JASSController : Controller
    {
        //
        // GET: /JASS/
        [Dependency]
        public IJassBL JassBL { get; set; }

        [Dependency]
        public ICapacitacionBL capaBL { get; set; }

        public ActionResult Index()
        {
            var id = 4;
            var lista = JassBL.ListarJassByIdsector(id);
            return PartialView(lista);
        }

       


        //
        // GET: /JASS/Details/5

        public ActionResult Details(int id)
        {
            var jass = JassBL.getFromJASSbyId(id);
            return View(jass);
        }

        public ActionResult Lista_Capacitaciones(int id)
        {
            var idjass = id;
            ViewBag.id = idjass;
            var listi = capaBL.ListarCapacitacionByIdJass(idjass);
            return View(listi);
        }




        //
        // GET: /JASS/Create

        public ActionResult Create()
        {
            var jass = new JASS();
            var ciu = new Ciudadano();
            var detalle = new ConsejoDirectivo() { Ciudadano = ciu };

            jass.ConsejoDirectivoes.Add(detalle);

            return View();
        }

        //
        // POST: /JASS/Create

        [HttpPost]
        public ActionResult Create(JASS Jass, HttpPostedFileBase Acta)
        {
            try
            {
                // TODO: Add insert logic here

                //if (Acta != null && Acta.ContentLength > 0)
                //{

                //    int length = Acta.ContentLength;
                //    byte[] buffer = new byte[length];

                //    Acta.InputStream.Read(buffer, 0, length);
                //    Jass.Acta = buffer;
                //    //Jass.Croquis = buffer;
                //    //Jass.Reglamento = buffer;
                //    //Jass.PlanAnual = buffer;

                //}

                JassBL.agregarJASS(Jass);

                var result = new
                {
                    msg = "El Jass fue Creado Correctamente",
                    exito = true
                };

                return Json(result, JsonRequestBehavior.AllowGet);

            }
            catch (SystemException ex)
            {
                var result = new
                {
                    msg = ex.Message,
                    exito = false
                };

                return Json(result, JsonRequestBehavior.AllowGet);

            }
        }

        //
        // GET: /JASS/Edit/5

        public ActionResult Edit(int id)
        {
            var jass = JassBL.getFromJASSbyId(id);
            return View(jass);
        }

        //
        // POST: /JASS/Edit/5

        [HttpPost]
        public ActionResult Edit(JASS jass, FormCollection collection)
        {
            try
            {
                JassBL.modificarJASS(jass);

                var result = new
                {
                    msg = "La Información fue Guardada Correctamente",
                    exito = true
                };

                return Json(result, JsonRequestBehavior.AllowGet);
            }
            catch (SystemException ex)
            {
                var result = new
                {
                    msg = ex.Message,
                    exito = false
                };

                return Json(result, JsonRequestBehavior.AllowGet);

            }
        }

        //
        // POST: /JASS/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
